package com.taikang.hmp.hbusiness.doctor.setbase.action.intface;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.taikang.hmp.frame.common.ErrorConstant;
import com.taikang.hmp.frame.common.TKException;
import com.taikang.hmp.frame.common.datastructre.Dto;
import com.taikang.hmp.frame.common.datastructre.support.BaseDto;
import com.taikang.hmp.frame.common.datastructre.support.ResponseDto;
import com.taikang.hmp.frame.common.web.action.BaseAction;
import com.taikang.hmp.hbusiness.doctor.setbase.service.IVersionService;

public class VersionAction extends BaseAction {
	private static final long serialVersionUID = 1L;

	private static Logger logger = LoggerFactory.getLogger(VersionAction.class);

	private IVersionService iVersionService;

	public IVersionService getiVersionService() {
		return iVersionService;
	}

	public void setiVersionService(IVersionService iVersionService) {
		this.iVersionService = iVersionService;
	}

	@Override
	public String executeAction() {
		if ("getVersion".equals(requestDto.getMethod())) {
			logger.info("--获取APP版本号 getVersion method -- ");
			return getVersion();
		} else {
			throw new TKException("no support method:" + requestDto.getMethod());
		}
	}

	private String getVersion() {
		ResponseDto responseDto = new ResponseDto();

		// 获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		List<Dto> resultList= iVersionService.getVersion(paramDto);
		if(resultList.size()<1){
			responseDto.addErrorCode(ErrorConstant.HD_NOT_VERSION);
			super.setDataMap(responseDto);
			return SUCCESS;
		}
		Dto resultDto = new BaseDto();
		resultDto.put("resultlist", resultList);
		responseDto.pushResultDto(resultDto);
		super.setDataMap(responseDto);
		return SUCCESS;
	}

}
